package com.umerclass.ui.action;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.umerclass.R;
import com.umerclass.frame.model.InfoResult;
import com.umerclass.frame.ui.fragment.BaseFragment;
import com.umerclass.ui.anmo.adapter.MyFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ActionFragment extends BaseFragment {

    @BindView(R.id.linear_search)
    LinearLayout linearSearch;
    @BindView(R.id.tab)
    TabLayout tab;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.view)
    View view;
    private List<String> titles = new ArrayList<>();
    private MyFragmentPagerAdapter myFragmentPagerAdapter;
    private ArrayList<Fragment> fragments = new ArrayList<>();

    @Override
    public boolean isImmersionBarEnabled() {
        return false;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_action;
    }

    @Override
    public void init() {
        settStateBar();
        titles.add("近期活动");
        titles.add("所有活动");
        fragments.add(JinQiFragment.newInstance());
        fragments.add(AllActionFragment.newInstance());
        myFragmentPagerAdapter = new MyFragmentPagerAdapter(this.getChildFragmentManager());
        myFragmentPagerAdapter.setFragments(fragments);
        myFragmentPagerAdapter.setTitles(titles);
        viewpager.setAdapter(myFragmentPagerAdapter);
        tab.setupWithViewPager(viewpager);
        viewpager.setOffscreenPageLimit(2);
    }

    @Override
    public void loadData() {

    }

    @OnClick({R.id.linear_search})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.linear_search:
                Intent intent = new Intent(getActivity(), SearchActionTeacherActivity.class);
                startActivity(intent);
                getActivity().overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onSuccess(int what, InfoResult t) {

    }

    @Override
    protected void onFail(int what, InfoResult t) {

    }

    private void settStateBar() {
        int result = 0;
        int resourceId = this.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = this.getResources().getDimensionPixelSize(resourceId);
            showToast("gaodu" + result);
            LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            linearParams.height = result;
            view.setLayoutParams(linearParams);
        } else {

        }
    }
}
